<?php

class Application_Model_RoundSettingsTbl extends Zend_Db_Table_Abstract
{
	protected $_name = 'round_settings';
	
	function checkIfClassAndRaceAreSelected($user_id)
    {
        $select = $this->_db->select()
                            ->from($this->_name, array('user_fk'))
                            ->where('user_fk=?',$user_id)
                            ->where("class_fk=0 OR race_fk=0");
        $result = $this->getAdapter()->fetchOne($select);
        if($result){
            return false; //race not selected
        }
        return true; //return true if class_fk or race_fk != 0 => RACE SELECTED
    }
    
    function checkIfUserExists($user_id)
    {
    	$select = $this->_db->select()
                            ->from($this->_name,array('user_fk'))
                            ->where('user_fk=?',$user_id);
        $result = $this->getAdapter()->fetchOne($select);
        if($result){
            return true;
        }
        return false;
    }
    
    
    
    function getRoundSettingsByUserID($user_id){
    	$select = $this->_db->select()
                            ->from($this->_name,array('user_fk','alias','race_fk','class_fk'))
                            ->where('user_fk=?',$user_id);
    	$result = $this->getAdapter()->fetchRow($select);
    	return $result;
    }
    
 	function checkIfAliasExists($alias)
    {
    	$select = $this->_db->select()
                            ->from($this->_name,array('alias'))
                            ->where('alias=?',$alias);
        $result = $this->getAdapter()->fetchOne($select);
        if($result){
            return true;
        }
        return false;
    }

}